<%@ Reference Control="~/Manager/Lib/Controls/Car.ascx" %>
<%@ Page language="c#" Inherits="Dimok.Aspx.Manager.Underwriting.Decision" CodeFile="Decision.aspx.cs" %>
<%@ Register TagPrefix="Car" TagName="Car" Src="/Manager/Lib/Controls/Car.ascx" %>
<%@ Register TagPrefix="LOAN" TagName="BUYERSORDER" Src="/Manager/Lib/Controls/BuyersOrder.ascx" %>
<%@ Register TagPrefix="LOAN" TagName="TRUTHINLENDING" Src="/Manager/Lib/Controls/TruthInLending.ascx" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" > 
<HTML>
<HEAD>
<TITLE>Decision</TITLE>
<META name="GENERATOR" Content="Microsoft Visual Studio .NET 7.1">
<META name="CODE_LANGUAGE" Content="C#">
<META name=vs_defaultClientScript content="JavaScript">
<META name=vs_targetSchema content="http://schemas.microsoft.com/intellisense/ie5">
<?XML:NAMESPACE PREFIX="COOL"/>
<LINK rel="stylesheet" type="text/css" href="/CSS/Outlook.css">
<STYLE>
cool\:tip{behavior: url(/Include/HTC/cooltip_js.htc)}
INPUT{overflow-x:visible;width:100%}
LEGEND {BEHAVIOR: url(/Include/HTC/Toggle.htc);COLOR:navy;FONT-WEIGHT:bold}
TD{white-space:nowrap }
.bigList{behavior:URL(/include/htc/BigList.htc)}
.RO{FONT-WEIGHT: bold}
.Numeric{TEXT-ALIGN: right}
.neg{color:darkred}
.bar{color:navy}
INPUT.neg{border:1 solid black}
</STYLE>
<SCRIPT language="javascript" src="/include/common.js"></SCRIPT>
<SCRIPT language="javascript" src="/include/RDS.js"></SCRIPT>
<SCRIPT language="javascript" src="/include/SOAP.js"></SCRIPT>
<SCRIPT language="javascript" src="/include/XML.js"></SCRIPT>
<SCRIPT language="javascript" src="/include/Events.js"></SCRIPT>
<SCRIPT language="javascript" src="/include/VIN.js"></SCRIPT>
<SCRIPT language="javascript" src="../Common/Common.js"></SCRIPT>
<SCRIPT language="javascript" src="../Common/Events.js"></SCRIPT>
</HEAD>
<BODY onload="page_Load()">
<COOL:TIP id="oTip" avoidmouse="true" DURATION="60"></COOL:TIP>
<XML id="xmlLoanInfo" Runat="server"></XML>
<XML id="xmlLoanInfoTIL" Runat="server"></XML>
<XML id="xmlConditions" Runat="server"></XML>
<XML id="xmlConditionList" Runat="server"></XML>
<XML id="xmlCreditInfo" runat="server"></XML>
<BUTTON onclick="pullCredit(true)">Pull credit</BUTTON>
<BUTTON onclick="faxCallback()">Fax</BUTTON>
<TABLE id="tblLoanInfo" cellpadding="0" cellspacing="0" border="0" width="1%" style="BORDER-COLLAPSE: collapse">
	<COL width="1%"><COL width="1%" align="right"><COL width="100%">
	<TR><TD colspan="100">
		<FIELDSET>
			<LEGEND state="+">
				<LABEL style="VERTICAL-ALIGN: middle;">Dealer</LABEL>
				<SELECT  style="VERTICAL-ALIGN: middle;" id="selDealers" onchange="selectSalesPerson(this)" dataSrc="#xmlLoanInfo" datafld="DealerID" runat="server" NAME="selDealers"></SELECT>
			</LEGEND>
			<TABLE>
				<TR><TD>Sales Person
						<TD colspan="100" align="left">
							<SELECT id="selSalesPersons" dataSrc="#xmlLoanInfo" datafld="DealerSalesPersonID" runat="server" NAME="selSalesPersons"></SELECT>
							Phone/Fax <SPAN datasrc="#xmlLoanInfo" datafld="DealerPhone" tabindex="-1" class="TextBox"></SPAN> /
							<SPAN datasrc="#xmlLoanInfo" datafld="DealerFax" tabindex="-1" class="TextBox"></SPAN>
				<TR><TD>Breakdown Code
						<TD colspan="100" align="left">
							<SELECT id="selBreakdownCodes" dataSrc="#xmlLoanInfo" datafld="BreakdownCode_F" runat="server" NAME="selBreakdownCodes"></SELECT>
				<TR><td>Contract Holder</td>
						<TD colspan="100" align="left">
							<SELECT datasourceid="dsContractHolders" DataTextField="Nick" DataValueField="ID" dataSrc="#xmlLoanInfo" datafld="ContractHolderID" runat="server">
								<option value=""></option>
							</SELECT>
				</TR>
			</TABLE>
		</FIELDSET>
	<TR><TD colspan="100">
		<FIELDSET>
			<LEGEND state="+"><LABEL>Credit</LABEL></LEGEND>
			<TABLE>
				<TR><TD>Mortgage Late<TD><INPUT datasrc="#XmlCreditInfo" datafld="MortgageLate" type="checkbox" style="width:1.5em">
				<TR><TD>Previous Repos<TD><INPUT datasrc="#XmlCreditInfo" datafld="RepoCount">
				<TR><TD>Open BK<TD><INPUT datasrc="#XmlCreditInfo" datafld="OpenBK" type="checkbox">
				<TR><TD>Phone/Utility Coll.<TD><INPUT datasrc="#XmlCreditInfo" datafld="PhoneUtilityCollection" type="checkbox">
			</TABLE>
		</FIELDSET>
	<TR><TD colspan="100">
		<FIELDSET>
			<LEGEND state="+"><LABEL>Stability</LABEL></LEGEND>
			<TABLE>
				<TR><TD>SSN -> DL<TD><INPUT datasrc="#XmlCreditInfo" datafld="SSN_DL" type="checkbox" style="width:1.5em">
				<TR><TD>Address Matches<TD><INPUT datasrc="#XmlCreditInfo" datafld="AddressMatches" type="checkbox" style="width:1.5em">
				<TR><TD>Anywho<TD><INPUT datasrc="#XmlCreditInfo" datafld="AnyWho" type="checkbox" style="width:1.5em">
				<TR><TD>DL Suspended<TD><INPUT datasrc="#XmlCreditInfo" datafld="DLSuspended" type="checkbox" style="width:1.5em">
			</TABLE>
		</FIELDSET>
	<TR><TD colspan="100">
		<FIELDSET>
			<LEGEND state="+"><LABEL>Conditions</LABEL></LEGEND>
			<TABLE datasrc="#xmlConditions" width="100%" cellpadding="0" cellspacing="0">
				<TBODY><TR>
					<TD style="BACKGROUND-COLOR: white;border:1 solid black" width="100%">
						<SPAN datafld="Lable" style="width:expression(innerText?'100%':'0%');color:darkred"></SPAN>
						<INPUT datafld="LableEdit" onchange="return updateCustomCondition(this)" style="width:expression(value?'100%':'0%');BORDER:none">
					<TD><INPUT type="button" value="Delete" onclick="deleteCondition(this)" tabindex="-1">
				</TR></TBODY>
				<TFOOT>
					<TR><TD><INPUT onupdate="addCondition(this)" id="txtAddCondition" style="BEHAVIOR: URL(/include/HTC/BigList.htc); OVERFLOW-X: visible;width:100%" xmlSrc="xmlConditionList" valueField="ID" textField="Lable" loose></TD></TR>
				</TFOOT>
			</TABLE>
		</FIELDSET>
	<TR><TD colspan="100"><CAR:CAR runat="server" id="car" onvinchange='UF(null,"VIN",event.VIN||null,"XmlLoanInfo")' /></TD>
	<TR><TD  style="PADDING:2px 0PX">Miles/Year
			<TD align="right"><SPAN class="RO" dataSrc="#xmlLoanInfoTIL" datafld="MilesPerYear" preset="currency" noDollar></SPAN>
			<TD></TD>
<TR><TD colspan="100"><TABLE width="100%"><TR><TD width="50%"><HR><TH nowrap class="bar">Terms<TD width="50%"><HR></TABLE>
	<TR><TD>Advance
			<TD><SPAN dataSrc="#xmlLoanInfoTIL" datafld="AdvancePercent_Gross"  class="RO"></SPAN>
			<TD>%<B style="COLOR: firebrick">[<INPUT dataSrc="#xmlLoanInfoTIL" datafld="AdvancePercentCalc" FieldName="AdvancePercentOverride" size="3" class="Numeric" style="width:2em" style="COLOR: firebrick" numeric>]</B>
					<IMG dataSrc="#xmlLoanInfoTIL" datafld="AdvancePercentOverrideFlag" src="/images/blank16x16.gif" title="History" class="TipMe" onclick="history(this,'AdvancePercentOverride')" width="16" height="16">

	<TR><TD>AddOn Rate
			<TD><SPAN dataSrc="#xmlLoanInfoTIL" datafld="AddOnRateMax"  class="RO"></SPAN>
			<TD>%<SELECT dataSrc="#xmlLoanInfoTIL" datafld="AddOnRateOverride" style="COLOR: red" numeric><OPTION></OPTION><OPTION value='11.00'>11.00</OPTION><OPTION value='11.50'>11.50</OPTION><OPTION value='12.00'>12.00</OPTION><OPTION value='12.50'>12.50</OPTION><OPTION value='13.00'>13.00</OPTION><OPTION value='13.50'>13.50</OPTION><OPTION value='14.00'>14.00</OPTION><OPTION value='14.50'>14.50</OPTION><OPTION value='15.00'>15.00</OPTION><OPTION value='15.50'>15.50</OPTION><OPTION value='16.00'>16.00</OPTION><OPTION value='16.50'>16.50</OPTION><OPTION value='17.00'>17.00</OPTION></SELECT>
					<IMG dataSrc="#xmlLoanInfoTIL" datafld="AddOnRateOverrideFlag" src="/images/blank16x16.gif" title="History" class="TipMe" onclick="history(this,'AddOnRateOverride')" width="16" height="16">
	<TR><TD><B>Profit:</B>
			<TD align="right" class="RO"><SPAN dataSrc="#xmlLoanInfoTIL" datafld="Profit"  preset="currency" showZeros></SPAN>
			<TD> (Is Rule 78 <input type="checkbox" dataSrc="#xmlLoanInfo" dataFld="IsRule78" style="border:none;width:auto;vertical-align:middle" />)</TD>
</TABLE>
<br />
<LOAN:BUYERSORDER ID="bo" ondecisionchanged="reloadDecisionTIL(arguments.callee.caller.arguments);pc.reloadPC()" runat="server" />
<LOAN:PurchaseContract ID="pc" runat="server" />
<LOAN:TRUTHINLENDING ID="til" onTILChanged="reloadDecisionTIL(arguments.callee.caller.arguments);pc.reloadPC()" runat="server" />

<FIELDSET style="width:1%" id="tblDisb" style="display:block">
	<LEGEND state="+"><LABEL>Disbursement (To dealer:<SPAN dataSrc="#xmlLoanInfoTIL" datafld="AdvanceAmount_Net" preset="currency"></SPAN>)</LABEL></LEGEND>
	<TABLE style="display:none">
		<COL align="right">
		<TR><TD nowrap><B>Amount Financed</B><TD class="RO" align="right"><SPAN dataSrc="#xmlLoanInfoTIL" datafld="AmountFinanced" preset="currency">000000.00</SPAN>
		<TR><TD nowrap><B>Gross Advance</B><TD class="RO" align="right"><SPAN dataSrc="#xmlLoanInfoTIL" datafld="AdvanceAmount_Gross" preset="currency"></SPAN>
		<TR><TD>Doc Stamps
				<TD align="right" class="neg"><SPAN dataSrc="#xmlLoanInfoTIL" datafld="DocStamps" preset="currency" showZeros class="neg"></SPAN>
		<TR><TD>Trackers Fee
				<TD align="right" class="neg"><SPAN dataSrc="#xmlLoanInfoTIL" datafld="TrackersFee" preset="currency" showZeros class="neg"></SPAN>
		<TR><TD>Processing Fee
				<TD align="right" class="neg"><SPAN dataSrc="#xmlLoanInfoTIL" datafld="ProcessingFee" preset="currency" showZeros class="neg"></SPAN>
		<TR><TD>PPP
				<TD align="right" class="neg"><SPAN dataSrc="#xmlLoanInfoTIL" datafld="PPP"  preset="currency" showZeros class="neg"></SPAN>
		<TR><TD>Discount
				<TD align="right" class="neg"><SPAN dataSrc="#xmlLoanInfoTIL" datafld="DiscountAmount_UpFront"  preset="currency" showZeros class="neg"></SPAN>
		<TR><TH><DIV style="FONT-SIZE: 1pt; WIDTH: 100%; BORDER-BOTTOM: black thin groove"></DIV></TH>
		<TR><TD nowrap class="RO">Total To Dealer<TD class="RO" align="right"><SPAN dataSrc="#xmlLoanInfoTIL" datafld="AdvanceAmount_Net" preset="currency" class="Numeric"></SPAN>
	</TABLE>
</FIELDSET>
<FIELDSET style="width:1%" id="tblOwned">
	<LEGEND state="+"><LABEL>Owned To Dealer: (<SPAN dataSrc="#xmlLoanInfoTIL" datafld="OwnedToDealer" preset="currency"></SPAN>)</LABEL></LEGEND>
	<TABLE style="display:none"><COL align="right"><COL align="right">
		<TR><TD>Trackers
				<TD align="right" class="neg"><SPAN dataSrc="#xmlLoanInfoTIL" datafld="TrackersWithhold" preset="currency" showZeros class="neg"></SPAN>
		<TR><TD>Discount<TD nowrap><SPAN dataSrc="#xmlLoanInfoTIL" datafld="DiscountAmount_BackEnd" preset="currency" showZeros class="neg"></SPAN>
	</TABLE>
</FIELDSET>
<BR>
<FIELDSET style="width:1%" id="tblTIL">
	<LEGEND state="+"><LABEL>Truth-In-Lending (Payment:<SPAN dataSrc="#xmlLoanInfoTIL" datafld="Payment" class="RO" preset="currency"></SPAN>)</LABEL></LEGEND>
	<DIV style="display:none">
<TABLE border="0">
	<TR><TD colspan="2">Term(mos)
				<SELECT dataSrc="#XmlLoanInfoTIL" datafld="LoanTerm"><OPTION value='12'>12</OPTION><OPTION value='18'>18</OPTION><OPTION value='24'>24</OPTION><OPTION value='30'>30</OPTION><OPTION value='36'>36</OPTION><OPTION value='42'>42</OPTION><OPTION value='48'>48</OPTION><OPTION value='54'>54</OPTION><OPTION value='60'>60</OPTION><OPTION value='66'>66</OPTION><OPTION value='72'>72</OPTION></SELECT>
				| Pmts/Mos <select dataSrc="#XmlLoanInfoTIL" dataFld="PaymentsPerMonth"><option Value="1">1</option><option Value="2">2</option></select>
	<TR><TD>Contract Date
			<TD align="right"><INPUT dataSrc="#XmlLoanInfoTIL" datafld="ContractDate_F" size="10" style="width:auto" null id="txtContractDate">
	<TR><TD>1st Pmt Date<INPUT onchange="var txt=getParentTR(this).all['txtFPD'];txt.value=dateAdd('dd',this.value,txtContractDate.value);return UF(txt)" style="width:2ex;overflow-x:visible" dataSrc="#XmlLoanInfoTIL" datafld="DaysTo1stPayment">
			<TD align="right"><INPUT dataSrc="#XmlLoanInfoTIL" datafld="FirstPaymentDate_F" size="10" style="width:auto" id="txtFPD"></TD>
	<TR><TD nowrap>APR<TD class="RO" align="right"><SPAN dataSrc="#xmlLoanInfoTIL" datafld="APR" showZeros></SPAN><TD>%</TD>
	<TR><TD nowrap>AddOn<TD class="RO" align="right"><SPAN dataSrc="#xmlLoanInfoTIL" datafld="AddOnRateByPayment" showZeros></SPAN><TD>%</TD>
	<TR><TD>Payment
			<TD nowrap align="right"><INPUT dataSrc="#XmlLoanInfoTIL" datafld="Payment" FieldName="PaymentOverride" size="10" numeric>
					<IMG dataSrc="#XmlLoanInfoTIL" datafld="PaymentOverrideFlag" src="/images/buttons/blank1x1.gif" title="History" class="TipMe" onclick="history(this,'PaymentOverride')"></TD>
	<TR><TD nowrap>Finance Charge<TD class="RO" align="right"><SPAN dataSrc="#xmlLoanInfoTIL" datafld="FinanceCharge" preset="currency" showZeros>00000.00</SPAN>
	<TR><TD nowrap>Amount Financed<TD class="RO" align="right"><SPAN dataSrc="#xmlLoanInfoTIL" datafld="AmountFinanced" preset="currency" showZeros></SPAN>
	<TR><TD nowrap>Total Of Payments<TD class="RO" align="right"><SPAN dataSrc="#xmlLoanInfoTIL" datafld="TotalPayments" preset="currency" showZeros></SPAN>
	<TR><TD nowrap>Total Sales Price<TD class="RO" align="right"><SPAN dataSrc="#xmlLoanInfoTIL" datafld="TotalSalesPrice" preset="currency" showZeros></SPAN>
</TABLE>
<TABLE datasrc="#XmlPayments" cellpadding="0" cellspacing="0" style="BORDER-COLLAPSE: collapse" border="1" bordercolor="ButtonShadow" style="BEHAVIOR: url(/Include/HTC/rowover_js.htc)" selectable="1">
	<THEAD valign="top"><TH>Pmt</TH><TH>Mos</TH><TH>Interest</TH><TH>Principle</TH><TH>Balance</TH><TH>Finance Charge</TH></THEAD>
	<TR align="right">
		<TD><SPAN datafld="PaymentNumber"></SPAN></TD>
		<TD><SPAN datafld="Mos"></SPAN></TD>
		<TD><SPAN datafld="ToInterest"></SPAN></TD>
		<TD><SPAN datafld="ToPrinciple"></SPAN></TD>
		<TD><SPAN datafld="RemainingPrinciple"></SPAN></TD>
		<TD><SPAN datafld="FinanceCharge"></SPAN></TD>
	</TR>
</TABLE>
	</DIV>
</FIELDSET>
<DIV id="divRegHist" style="display:none">
<TABLE datasrc="#xmlReqHist" style="FONT: statusbar; BORDER-COLLAPSE: collapse" border="1" bordercolor="black" onreadystatechange="if(document.body.funcResize)document.body.funcResize()">
	<THEAD><TR><TH>Value</TH><TH>When</TH><TH>Who</TH></TR></THEAD>
	<TR>
		<TD nowrap><SPAN datafld="Value"></SPAN></TD>
		<TD nowrap><SPAN datafld="When"></SPAN></TD>
		<TD nowrap><SPAN datafld="Who"></SPAN></TD>
	</TR>
</TABLE>
<XML id="xmlReqHist">[xml]</XML>
</DIV>
<TABLE>
	<TR><TD><LABEL for="chkDeclined">Declined</LABEL>
			<TD colspan="100" align="left"><INPUT id="chkDeclined" dataSrc="#xmlLoanInfo" datafld="Declined" type="checkbox" style="border:none;width:1.5em">
</TABLE>
<XML id="xmlPayments" runat="server"></XML>
<DS:ContractHoldersDataSource ID="dsContractHolders" runat="server" />
</BODY>
</HTML>
<SCRIPT language="javascript">
initWS("DECISION","Decision.asmx");
function page_Load(){
	attachToDealerChanged(reloadMe,ApplID());
	attachToVerTreeChanged(reloadConditions,ApplID());
	attachToDecisionInfoChanged(reloadDecisionTIL,ApplID());
	attachToKeyDown();
	initPreset();
	initInputs();
	UF_AddCallBack(reloadDecisionTIL);
	UF_AddCallBack(function(ret){bo.reloadTIL(ret)});
	UF_AddCallBack(function(){fireDecisionInfoChanged(ApplID());})
}
function doBookValueChange(){
	var ret = WS(CO("xmlLoanInfoTIL"),"","");
	if( showSOAPError(ret) )return false;
	reloadDecisionTIL(ret);
}
function pullCredit(){
	var ret = WS(CO("PullCredit"));
	if( showSOAPError(ret) )return false;
	fireCreditRepulled(ApplID());
}
function faxCallback(){
	showModalDialog("CallBack.aspx?ApplID="+ApplID()+"&IsFax=1&NoLock=1",{opener:top});
}
function changeSalesTax(){
	var tax = prompt("Sales Tax:",xmlLoanInfo.recordset("SalesTaxPercent"));
	if( !tax )return;
	UF(null,"SalesTaxPercent",tax,"xmlLoanInfo");
}
function reloadDecisionTIL(ret,el,fieldName,fieldValue,wsMethod){
	if( callSelf() )return;
	if( wsMethod && !wsMethod.match(/loaninfo/i) )return;
	if( !ret || !ret.value ){
		ret = WS(CO("XmlLoanInfo"),"","");
		if( showSOAPError(ret) )return false;
	}
	if( !xmlLoanInfoTIL.loadXML(ret.value) )alert("Error while loading TIL");
	if( !xmlLoanInfo.loadXML(ret.value) )alert("Error while loading TIL");
	setTimeout("initPreset(document.body);try{activeElement.select()}catch(e){}",500);
	reloadPayments();
}
function reloadPurchaseContract(){
}
function reloadPayments(){
	var ret = WS(cb,"PaymentsSchedule");
	// Local
	function cb(ret){
		if( showSOAPError(ret) )return false;
		xmlPayments.loadXML(ret.value);
		xmlPayments.state = xmlPayments.state;
	}
}
function reloadMe(eventObject){
	location.reload();
}
// ******** Conditions **********
function addCondition(el){
	if( !checkWS(true) )return setTimeout(function(){return addCondition(el);},500);
	var condID = el.Value || 0;
	var condLable = el.Text;
	if( !condLable )return;
	var ret = WS(CO("AddCondition"),condID,condLable);
	if( showSOAPError(ret) )return false;
	el.Text = "";
	updateConditions(ret.value);
	fireEvents(_eventObject(condID));
}
function deleteCondition(el){
	if( !checkWS(true) )return setTimeout(function(){return deleteCondition(el);},500);
	var condID = rsField(el,"ID").Value;
	var ret = WS(CO("DeleteCondition"),condID);
	if( showSOAPError(ret) )return false;
	updateConditions(ret.value);
	fireEvents(_eventObject(condID));
}
function updateCustomCondition(el){
	if( !checkWS(true) )return setTimeout(function(){return deleteCondition(el);},500);
	var condID = rsField(el,"ID").Value;
	var ret = WS(CO("UpdateCustomCondition"),condID,el.value);
	if( showSOAPError(ret) )return false;
	fireEvents(_eventObject(-1));
}
function updateConditions(xmls){
	xmlConditions.loadXML(xmls[0]);
	txtAddCondition.fillSelect(xmls[1]);
}
function reloadConditions(){
	var ret = WS(CO("ConditionsAll"));
	if( showSOAPError(ret) )return false;
	updateConditions(ret.value);
}
// ********* History *********
function history(el,fielName){
	var ret = WS(CO("GetColumnHistory"),null,null,null,null,fielName);
	if( showSOAPError(ret) )return false;
	el.coolTip = divRegHist.innerHTML.replace("[xml]",ret.value);
	el.fireEvent("onmouseover",event);
}
function fireEvents(eventObject){
	fireOnReloadVerTree(eventObject);
	fireDecisionInfoChanged(eventObject);
}
function _eventObject(verID){return {applID:ApplID(),reload:parseInt(verID)<=0}}
</SCRIPT>
